package com.wondersgroup.robot.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.wondersgroup.robot.po.RoQuestion;

/**
 * Data access object (DAO) for domain model class RoQuestion.
 * 
 * @see com.wondersgroup.robot.po.RoQuestion
 * @author MyEclipse Persistence Tools
 */

public class RoQuestionDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(RoQuestionDAO.class);

	// property constants
	public static final String ROQU_QUESTION = "roquQuestion";

	public static final String ROQU_ANSWER = "roquAnswer";

	public void save(RoQuestion transientInstance) {
		log.debug("saving RoQuestion instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(RoQuestion persistentInstance) {
		log.debug("deleting RoQuestion instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public RoQuestion findById(java.lang.String id) {
		log.debug("getting RoQuestion instance with id: " + id);
		try {
			RoQuestion instance = (RoQuestion) getSession().get(
					"com.wondersgroup.robot.po.RoQuestion", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(RoQuestion instance) {
		log.debug("finding RoQuestion instance by example");
		try {
			List results = getSession().createCriteria(
					"com.wondersgroup.robot.po.RoQuestion").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding RoQuestion instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from RoQuestion as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByRoquQuestion(Object roquQuestion) {
		return findByProperty(ROQU_QUESTION, roquQuestion);
	}

	public List findByRoquAnswer(Object roquAnswer) {
		return findByProperty(ROQU_ANSWER, roquAnswer);
	}

	public List findAll() {
		log.debug("finding all RoQuestion instances");
		try {
			String queryString = "from RoQuestion";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public RoQuestion merge(RoQuestion detachedInstance) {
		log.debug("merging RoQuestion instance");
		try {
			RoQuestion result = (RoQuestion) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(RoQuestion instance) {
		log.debug("attaching dirty RoQuestion instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(RoQuestion instance) {
		log.debug("attaching clean RoQuestion instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}